package com.ltsznh.android.anti_villain;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

import java.util.Stack;

public class AntiVillainReceiver extends BroadcastReceiver {
    private static Intent service;
    public static String IO = "I";
    public static String num = "";

    public static PhoneListener phoneListener = new PhoneListener();

    public static void init(Context context, Intent intent){
        if(phoneListener == null){
            phoneListener = new PhoneListener();
        }
        service = new Intent(context,AntiVillainService.class);
        context.startService(service);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
//        throw new UnsupportedOperationException("Not yet implemented");
        Log.v("dddd","broadcast onReceive!----------------------------");
        init(context,intent);

        if(intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)){
            num =  intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            IO = "O";
//            new ReadLog(context).start();
        }else {
            num = "";
            IO = "I";
        }

        Log.v("dddd","broadcast finished!----------------------------");





    }
}
